package com.xm.xmapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.android.volley.VolleyError;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Redeem_electronic_couponsRequest;
import com.xm.xmapp.response.bean.ResponseUserCouponsList;
import com.xm.xmapp.tools.Tools;

public class InputDHQActivity extends BaseActivity implements OnClickListener {
	private EditText content;
	private ImageView duihuan;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_inputdhq);
	}

	@Override
	public void initView() {
		content = (EditText) findViewById(R.id.duihuanma);
		duihuan = (ImageView) findViewById(R.id.duihuan);
	}

	@Override
	public void initData() {
		setMyTitle("兑换券");
	}

	@Override
	public void initEvent() {
		duihuan.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.duihuan:

			if (content.getText().toString().equals("")) {
				Tools.showMessage("请输入电子兑换码");
			} else {
				Redeem_electronic_couponsRequest requestBean = new Redeem_electronic_couponsRequest();
				requestBean.redeem_code = content.getText().toString();
				promptDialog.show();
				MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

					@Override
					public void onResponse(String response) {

						promptDialog.dismiss();
						ResponseUserCouponsList bean = JSON.parseObject(response, ResponseUserCouponsList.class);
						intent = new Intent(getApplicationContext(), ShowDHQActivity.class);
						intent.putExtra("bean", bean);
						intent.putExtra("redeem_code", content.getText().toString());
						content.setText("");
						startActivity(intent);
					}
				}, new DisssmissInterFace() {

					@Override
					public void putError(VolleyError error) {
						promptDialog.dismiss();
					}
				});
			}

			break;

		default:
			break;
		}
	}

}
